// pages/choose/choose.js
let datas = require('../../data/racquets-data');

Page({

  /**
   * 页面的初始数据
   */

  data: {
    multiArray: [
      ['性别', '男', '女'],
      ['握拍', '双反', '单反'],
      ['水平', '1.0-2.0', '2.0-3.0', '3.0-4.0', '4.0-5.0'],
      ['类型', '平击', '上旋', '平衡']
    ],
    multiIndex: [0, 0, 0, 0],
    matchList: [],
  },
  // 所有行业
  bindMultiPickerChange: function(e) {
    console.log(e.currentTarget.dataset);
    let array = e.currentTarget.dataset.array;
    console.log(e.detail.value);
    this.setData({
      multiIndex: e.detail.value
    });

    console.log(array[0][e.detail.value[0]]);


    var a = [];
    var b = [];
    var c = [];
    var d = [];

    if (array[0][e.detail.value[0]] == '男') {
      for (var i = 0; i < datas.racquets_data.length; i++) {
        var weight = parseInt(datas.racquets_data[i].weight);
        //if (weight >=100)
          a.push(datas.racquets_data[i]);
      }
    } else if (array[0][e.detail.value[0]] == '女') {
      for (var i = 0; i < datas.racquets_data.length; i++) {
        var weight = parseInt(datas.racquets_data[i].weight);
        var area = parseInt(datas.racquets_data[i].area);
        if (weight <=330 && area >=100)
          a.push(datas.racquets_data[i]);
      }
    }

    if (array[1][e.detail.value[1]] == '双反') {
      for (var i = 0; i < a.length; i++) {
        if (a[i].grip == 1 || a[i].grip == 2)
          b.push(a[i]);
      }
    } else if (array[1][e.detail.value[1]] == '单反') {
      for (var i = 0; i < a.length; i++) {
        if (a[i].grip == 1 || a[i].grip == 2)
          b.push(a[i]);
      }
    }


    if (array[2][e.detail.value[2]] == '1.0-2.0') {
      for (var i = 0; i < b.length; i++) {
        var balance = parseInt(b[i].balance_point);
        if (balance <= 6)
          c.push(b[i]);
      }
    } else if (array[2][e.detail.value[2]] == '2.0-3.0') {
      for (var i = 0; i < b.length; i++) {
        var balance = parseInt(b[i].balance_point);
        if (balance >= 3 && balance <= 8)
          c.push(b[i]);
      }
    } else if (array[2][e.detail.value[2]] == '3.0-4.0') {
      for (var i = 0; i < b.length; i++) {
        var balance = parseInt(b[i].balance_point);
        if (balance >= 4 && balance <= 10)
          c.push(b[i]);
      }
    } else if (array[2][e.detail.value[2]] == '4.0-5.0') {
      for (var i = 0; i < b.length; i++) {
        var balance = parseInt(b[i].balance_point);
        if (balance >= 6 && balance <= 12)
          c.push(b[i]);
      }
    } else if (array[2][e.detail.value[2]] == '5,0+') {
      for (var i = 0; i < b.length; i++) {
        var balance = parseInt(b[i].balance_point);
          c.push(b[i]);
      }
    }

    if (array[3][e.detail.value[3]] == '平击') {
      for (var i = 0; i < c.length; i++) {
        if (c[i].thread == '15/16' || c[i].thread == '16/18' || c[i].thread == '16/19' || c[i].thread == '18/19')
          //if (c[i].thread != '18/20')
          d.push(c[i]);
      }
    } else if (array[3][e.detail.value[3]] == '上旋') {
      for (var i = 0; i < c.length; i++) {
        if (c[i].thread == '16/20' || c[i].thread == '16/18' || c[i].thread == '16/19' || c[i].thread == '18/19')
       // if (c[i].thread != '15/16')
          d.push(c[i]);
      }
    } else if (array[3][e.detail.value[3]] == '平衡') {
      for (var i = 0; i < c.length; i++) {
        if (c[i].thread == '16/20' || c[i].thread == '18/19' || c[i].thread == '18/20' || c[i].thread == '16/18')
        // if (c[i].thread != '15/16' && c[i].thread != '18/20')
          d.push(c[i]);
      }
    } 
    //男5.0+ 1.0反

    this.setData({
      matchList: d
    });

  },

  toDetail(e) {
    console.log(e);
    let postId = e.currentTarget.dataset.pid;
    console.log(postId);
    wx.navigateTo({
      url: '/pages/detail/detail?postId=' + postId,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '匹配'
    })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})